package org.luffhat.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.luffhat.entity.User;
import org.luffhat.mapper.UserMapper;
import org.luffhat.response.R;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description
 * @Author ljb
 * @Date 2022-01-12
 */
@Api("hhhh123")
@RestController
public class Test {

    Logger logger = LoggerFactory.getLogger(Test.class);

    @Autowired
    private UserMapper userMapper;

    @ApiOperation(value = "所有讲师列表")
    @GetMapping("/test/{id}")
    public List<User> test(@PathVariable String id) {
        logger.info("info日志");
        logger.error("error日志");
        logger.debug("debug日志");
        System.out.println(id);
        List<User> users = userMapper.selectList(null);
        return users;
    }

    @ApiOperation(value = "所有讲师列表")
    @GetMapping("/queryUserById/{id}")
    public R<User> queryUserById(@PathVariable String id) {

//        int i = 10 / 0;

        System.out.println(id);
        User user = userMapper.selectById(id);
        return R.data(user);
    }

    @ApiOperation(value = "测试返回结果")
    @GetMapping("/testResponse")
    public R<Map<String, Object>> testResponse() {

        Map<String, Object> map = new HashMap<>();

        HashMap<Object, Object> objectObjectHashMap = new HashMap<>();
        objectObjectHashMap.put("11","22");
        map.put("list", Arrays.asList(1,2,3,4));
        map.put("map",objectObjectHashMap);
        map.put("str",new String());
        map.put("boolean",new Boolean(true));
        map.put("number",new Integer(1));
        map.put("double",new Double(2));
        return R.data(map);
    }


}
